<template>
  <router-view />
</template>

<script setup>
import useSettingsStore from '@/store/modules/settings';
import { handleThemeStyle } from '@/utils/theme';
import { getIndexPlatformInfo } from '@/api/appv2/appv2.js';
const store = useSettingsStore();
const getInfo = async () => {
  const res = await getIndexPlatformInfo();
  // document.title = res.data.title
  store.setPlatformInfo(res);
  store.setTitle(res.data.title);
  setFavicon(res.data.favicon);
  store.setMenuIcon({ bigImg: res.data.logo, smallImg: res.data.smalllogo });
};
getInfo();
const setFavicon = (newIconUrl) => {
  // 创建新的 link 标签
  var newLink = document.createElement('link');
  newLink.rel = 'icon';
  newLink.type = 'image/x-icon';
  newLink.href = newIconUrl;

  // 获取并移除原有的 favicon link（如果有多个，可能需要更精确的选择器）
  var oldLinks = document.querySelectorAll('link[rel="icon"]');
  for (var i = 0; i < oldLinks.length; i++) {
    oldLinks[i].parentNode.removeChild(oldLinks[i]);
  }

  // 将新创建的 link 插入到 head 中
  document.head.appendChild(newLink);
};
onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme);
  });
});
</script>
<style>
@import './assets/styles/mybase.css';
</style>
